package manager;

import entity.Semester;
import iface.IManager;
import java.util.ArrayList;

/**
 *
 * @author Noi
 */
public class SemesterManager implements IManager<Semester> {

    private ArrayList<Semester> semesterList;

    public SemesterManager() {
        this.semesterList = new ArrayList<Semester>();
    }

    @Override
    public boolean add(Semester semester) {
        return this.semesterList.add(semester);
    }

    @Override
    public boolean remove(Semester semester) {
        return this.semesterList.remove(semester);
    }

    @Override
    public Semester replace(int index, Semester semester) {
        return this.semesterList.set(index, semester);
    }
    
    @Override
    public int size() {
        return this.semesterList.size();
    }
    
    @Override
    public Semester get(int index) {
        return this.semesterList.get(index);
    }
    
    @Override
    public Semester getById(int semesterID) {
        for(Semester obj: this.semesterList) {
            if(obj.getSemesterID() == semesterID) return obj;
        }
        return null;
    }
    
    @Override
    public Semester getByName(String SemesterName) {
        for(Semester obj: this.semesterList) {
            if(obj.getSemesterName().equals(SemesterName)) return obj;
        }
        return null;
    }
    
    @Override
    public void setVisible(Semester semester, boolean value) {
        for(Semester obj: this.semesterList) {
            if(obj.getSemesterID() == semester.getSemesterID()) obj.setStatus(value);
        }
    }
    
    public boolean contains(String semesterName) {
        for(Semester semester: this.semesterList) {
            if(semester.getSemesterName().equals(semesterName)) return true;
        }
        return false;
    }
}
